<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>投资记录</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
    <script type="text/javascript">
        function closeWin(){
            api.closeWin({
            });
        };
    </script>
</head>
<body>

    <div id="list"></div>

</body>

<script type="text/template" id="template">
<div class="licai-record">
    <ul>
        {{~it:value:index}}
        <li>
            <div class="aui-pull-left">
                <p class="name">{{=value.user_name}}</p>
                <p class="time">{{=value.create_time}}</p>
            </div>
            <div class="licai-record-r aui-pull-right money">{{=value.money}}
            </div>
        </li>
        {{~}}
    </ul>
</div>
</script>

<script type="text/javascript">

    var id = '';
    var load_count = '';

    apiready = function(){
        id = api.pageParam.id;
        // load_count = api.pageParam.load_count;

        addObserver();
        load_list();
    }

    function addObserver() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err){

            load_list(true);
        });
    }

    // 加载列表
    function load_list(n) {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });

        if (n) {
            page += 1;
        }else {
            page = 1;
        }

        api.ajax({
            url: webAddress+'/index.php?ctl=app_deal&act=load_list&time_limit='+id+'&page='+page,
            method: 'get',
        },function(ret, err){

            if (ret) {

                if (ret.status == 0) {
                    alert(ret.info);
                }else {
                    // alert( JSON.stringify( ret ) );

                    for (var i = 0; i < ret.load_list.length; i++) {
                        ret.load_list[i].user_name = hidden_name(ret.load_list[i].user_name);
                        ret.load_list[i].money = outputmoney(ret.load_list[i].money);
                        ret.load_list[i].create_time = getDate(ret.load_list[i].create_time);
                    }

                    updateList(ret.load_list, page, ret.load_list.length);

                    api.hideProgress();
                }
            } else {
                alert( JSON.stringify( err ) );
                api.hideProgress();
            }
        });
    }

    // doT
    function updateList(data, page, num){
        // alert($api.jsonToStr(data));
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');

        if (page == 1) {
            $api.html(list, html);

        }else {
            if (data == '') {
                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            $api.append(list, html);
        }

        api.parseTapmode();
    }

</script>
</html>
